import 'package:app/pages/index/index_controller.dart';
import 'package:app/shared/constants/common.dart';
import 'package:app/pages/components/moment.dart';
import 'package:app/pages/home/widget/card.dart';
import 'package:app/pages/home/widget/classies.dart';
import 'package:app/pages/home/widget/search.dart';
import 'package:app/pages/home/widget/title.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

class HomePage extends StatefulWidget {
  HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  final IndexController controller = Get.find<IndexController>();
  @override
  Widget build(BuildContext context) {
    super.build(context);
    return RefreshIndicator(
      onRefresh: _onRefresh,
      child: Padding(
          padding: EdgeInsets.symmetric(horizontal: sDefaultMarginPadding * 3),
          child: ListView(
            controller: controller.HomeControllerDropDown,
            children: [
              SearchWidget(),
              ClassiesCom(),
              GetBuilder(
                  init: controller,
                  builder: (IndexController controller) {
                    return CardCom(controllerArg: controller);
                  }),
              TitleCom(),
              GetBuilder(builder: (IndexController controller) {
                return MomentCom(ListData: controller.wonderfulList);
              }),
              SizedBox(
                height: 200,
              )
            ],
          )),
    );
  }

  // _onRefresh 下拉刷新回调
  Future<Null> _onRefresh() {
    return Future.delayed(Duration(seconds: 2), () {
      // 延迟5s完成刷新
      print("刷新了");
    });
  }
}
